package com.mall.controller;

import com.mall.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付控制器
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;

    /**
     * 支付宝支付
     * @param orderId 订单ID
     * @param redirect 支付完成后的回调地址
     */
    @GetMapping("/aliPay")
    public ResponseEntity<Void> aliPay(
            @RequestParam("orderId") Long orderId,
            @RequestParam("redirect") String redirect) {
        // 实际项目中，这里应该调用支付宝的SDK进行支付
        // 这里简化处理，直接重定向到回调地址，模拟支付结果
        String redirectUrl = redirect + "?orderId=" + orderId + "&payResult=true";
        
        HttpHeaders headers = new HttpHeaders();
        headers.add("Location", redirectUrl);
        return new ResponseEntity<>(headers, HttpStatus.FOUND);
    }
} 